-- BloodyTestbed.lua
-- Created by huanghr July/13/2016
-- 血腥试验台

require "game/ui/form/dungeon/special/UISkyBloodyTestbed"

-- 初始化
function initBloodyTestbed(self)
    self.item:removeAllChildren();

    local class = self.gridData.class;
    local buildingInfo = BuildingBonusM.queryBuildingView(class);

    if not buildingInfo then
        error("获取不到建筑查看配置，元素类型：" .. class);
        return;
    end

    local function onClicked(sender, eventType)
        if eventType == ccui.TouchEventType.began then
            if self.gridData.state == GRID_STATE_DISABLE then
                -- 已经失效，不处理
                return;
            end

            -- 更新建筑访问
            self:updateBuildingVisit();

            -- 打开实验台
            UIMgr.getCurrentScene():removeFormByName("UISkyBloodyTestbed");
            local uiForm = UISkyBloodyTestbed.create(self.gridData);
            UIMgr.getCurrentScene():addForm(uiForm);

            -- 音效
            AudioM.playFx("workshop_store");
        end
    end

    -- 建筑图标
    local iconPath = getLevelItemIconPath(buildingInfo["icon"]);

    self.icon = ccui.ImageView:create(iconPath);
    self.icon:setTouchEnabled(true);
    self.icon:addTouchEventListener(onClicked);
    self.item:addChild(self.icon);
    self.iconPath = iconPath;
end
